//
//  ZCInputAndBtnCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/3/26.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import "ZCInputAndBtnCell.h"
#import "TBCityIconFont.h"
#import <BlocksKit+UIKit.h>
@interface ZCInputAndBtnCell()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *inputTF;
@end


@implementation ZCInputAndBtnCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self setupSubViews];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setupSubViews {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    [self.btn setTitle:nil forState:UIControlStateNormal];
    self.btn.backgroundColor = [UIColor whiteColor];
    self.inputTF.delegate = self;
    [self.btn bk_addEventHandler:^(id sender) {
        self.secureTextEntry = !self.secureTextEntry;
    } forControlEvents:UIControlEventTouchUpInside];
}

// MARK: - UITextFieldDelegate

- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (self.endEditCallback) {
        self.endEditCallback(textField.text);
    }
}

- (void)setSecureTextEntry:(BOOL)secureTextEntry {
    _secureTextEntry = secureTextEntry;
    UIImage *icon = nil;
    if (secureTextEntry) {
        icon = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e645", 25, [generalToolBox getColorWithHexadecimalColorStr:@"0x999999"])];
    } else {
        icon = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e646", 25, [generalToolBox getColorWithHexadecimalColorStr:@"0x999999"])];
    }
    [self.btn setImage:icon forState:UIControlStateNormal];
    self.inputTF.secureTextEntry = secureTextEntry;
}

- (void)setPlaceholder:(NSString *)placeholder {
    _placeholder = placeholder;
    self.inputTF.placeholder = placeholder;
}

@end
